import wordcloud #导入词云库
import numpy as np
import matplotlib.pyplot as plt
import PIL
import re
with open(r'数据清洗数据.txt',encoding='GBK') as f:
    comment = f.readlines()
#导入图片
image1 = PIL.Image.open(r'pic.jfif')
MASK = np.array(image1)
WC = wordcloud.WordCloud(font_path = 'C:\\Windows\\Fonts\\STFANGSO.TTF',max_words=10000,mask = MASK,height= 400,width=400,background_color='white',repeat=False) #设置词云图对象属性
con = WC.generate(str(comment))
plt.imshow(con)
plt.axis("off")
plt.show()
WC.to_file("分析词云图.jpg")